<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="上传">
    <BasicForm @register="registerForm"> </BasicForm>
  </BasicModal>
</template>
<script lang="ts">
  import { defineComponent, ref, unref } from 'vue';
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { formSchema } from './data';
  import { BasicModal, useModalInner } from '/@/components/Modal';

  export default defineComponent({
    name: 'LogDrawer',
    components: { BasicModal, BasicForm },
    emits: ['success', 'register'],
    setup(_) {
      const isUpdate = ref(true);

      const [registerForm, { resetFields, setFieldsValue }] = useForm({
        labelWidth: 100,
        schemas: formSchema,
        showActionButtonGroup: false,
        //disabled: true,
      });

      const [registerModal, { setModalProps }] = useModalInner(async (data) => {
        resetFields();
        setModalProps({ confirmLoading: false });
        isUpdate.value = !!data?.isUpdate;
        if (unref(isUpdate)) {
          setFieldsValue({
            ...data.record,
          });
        }
      });
      return { registerModal, registerForm };
    },
  });
</script>
